package mainWindowSupport;

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;

import menuMaster.MenuBuilder;
import palette.*;
import actionHandlers.CloseHandler;
import utilities.Logging;

public class MainWindow extends JFrame {

	private static final long serialVersionUID = -2303006344184845201L;

	public MainWindow()
	{
		Logging.write(0, "test");
		this.setTitle("QP: A Shape Drawer");
		//MenuBar topMenu = new MenuBar();
		menuMaster.MenuBuilder topMenuBldr = new menuMaster.MenuBuilder("menubar.xml", MenuBuilder.BUILDMENUBAR);
		javax.swing.JMenuBar topMenu = topMenuBldr.getMenuBar();

		//Lay out the label and scroll pane from top to bottom.
		CanvasManager canvas = CanvasManager.getInst();  //added JD
		CanvasManager.getInst().addNewCanvas();
		//canvas.setLayout(new BoxLayout(canvas, BoxLayout.PAGE_AXIS));
		//JScrollPane scroll = new JScrollPane(canvas);
		//scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		//scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		//canvas.add(Box.createRigidArea(new Dimension(0,5)));
		//canvas.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		//canvas.addComponentListener(new CanvasListener());
		
		//ToolBar mainBar = ToolBar.getInst();
		menuMaster.MenuBuilder mainBarBldr = new menuMaster.MenuBuilder("toolbar.xml", MenuBuilder.BUILDTOOLBAR);
		javax.swing.JToolBar mainBar = mainBarBldr.getToolBar();
		
		//Put everything together, using the content pane's BorderLayout.
		Container contentPane = getContentPane();
		//contentPane.add(scroll, BorderLayout.CENTER);
		contentPane.add(mainBar, BorderLayout.NORTH);
		contentPane.add(canvas, BorderLayout.CENTER);
		
		
	    this.pack();
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.addWindowListener(new CloseHandler());				
		this.setJMenuBar(topMenu);
		this.setSize(850,650);
	}
	
	public void run()
	{
		this.setVisible(true);
	}
}